package cn.imu.appdevexperiment2020.Application.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import cn.imu.appdevexperiment2020.Application.api.ApiClient;
import cn.imu.appdevexperiment2020.Application.bean.user.ResetPwdReceiveBean;
import cn.imu.appdevexperiment2020.Application.bean.user.ResetPwdSendBean;
import cn.imu.appdevexperiment2020.Application.util.AuthUtil;
import cn.imu.appdevexperiment2020.R;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ResetPwdActivity extends AppCompatActivity {
    public static final String TAG="ResetPwd";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reset_pwd);
        Button resetPwd = findViewById(R.id.reset);
        TextView userIdTv=findViewById(R.id.userid);
        TextView passwordTv=findViewById(R.id.password3);
        TextView updateByTv=findViewById(R.id.updateBy);
        resetPwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userId= userIdTv.getText().toString();
                String password= passwordTv.getText().toString();
                String updataBy= updateByTv.getText().toString();
                ResetPwdSendBean resetPwdSendBean = new ResetPwdSendBean();
                resetPwdSendBean.setUserId(userId);
                resetPwdSendBean.setPassword(password);
                resetPwdSendBean.setUpdateBy(updataBy);
                Call<ResetPwdReceiveBean> call= ApiClient.getInstance(getApplicationContext()).getReturnData(AuthUtil.GetAuth(),resetPwdSendBean);
                call.enqueue(new Callback<ResetPwdReceiveBean>() {
                    @Override
                    public void onResponse(Call<ResetPwdReceiveBean> call, Response<ResetPwdReceiveBean> response) {
                        if(null!=response.body())
                        {
                            if(200==response.body().getCode())
                            {
                                Log.d(TAG, response.body().getMsg());
                                Toast.makeText(getApplicationContext(),"密码修改成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }else{
                                Toast.makeText(getApplicationContext(),response.body().getMsg(),Toast.LENGTH_SHORT).show();
                            }
                        }else
                            Toast.makeText(getApplicationContext(),"网络连接失败",Toast.LENGTH_SHORT).show();
                    }
                    @Override
                    public void onFailure(Call<ResetPwdReceiveBean> call, Throwable t) {
                        Toast.makeText(getApplicationContext(),"网络连接失败",Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}